package redis

import (
	"cloud-storage/global"
	"cloud-storage/lib"
	"context"
	"github.com/go-redis/redis/v8"
	"go.uber.org/zap"
)

// InitRedis 连接redis
func InitRedis() {
	client := redis.NewClient(&redis.Options{
		Addr:     lib.RedisSetting.Addr,
		Password: lib.RedisSetting.Password,
		DB:       lib.RedisSetting.DB,
	})
	_, err := client.Ping(context.Background()).Result()
	if err != nil {
		zap.L().Fatal("init redis failed")
		return
	}
	global.Redis = client
	zap.L().Info("init redis success")
}
